/**
 * Desenvolvido pela Fábrica de Software do CESUPA.
 * Todos os direitos reservados.
 */
package br.cesupa.fabsoft.nomedoprojeto.modules.helpmodule;

import br.cesupa.fabsoft.nomedoprojeto.modules.helpmodule.beans.HelpIndexBean;
import br.cesupa.fabsoft.nomedoprojeto.modules.helpmodule.entities.HelpTopic;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.model.SelectItem;

/**
 *
 * @author Breno Leite
 */
public class HelpTopicConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component,
            String value) {
        List<SelectItem> selectItens = new HelpIndexBean().getHelpTopics();
        for (SelectItem selectItem : selectItens) {
            HelpTopic helpTopic = (HelpTopic) selectItem.getValue();
            if (helpTopic.getTitle().equals(value)) {
                return helpTopic;
            }
        }

        return null;
    }

    public String getAsString(FacesContext context, UIComponent component,
            Object value) {
        HelpTopic helpTopic = (HelpTopic) value;
        return helpTopic.getTitle();
    }
}
